function res = treb_range_finder(px,py,vx,vy, height)
W = [px,py]; %makes vector of positions
p = W(1:2);% intitial position







options = odeset('Events', @events);

    function [value,isterminal,direction] = events(t,X)
       value = X(2)+height;
       
        isterminal = 1;
        direction = -1;
    end
clf
%      ode45(@projectile1,[0,10],[p(1),p(2),vx,vy],options);
%      legend('position x', 'position y', 'velocity x', 'velocity y') 
[T,M] = ode45(@projectile1,[0,10],[p(1),p(2),vx,vy],options);
dis = M(:,1);
res = dis(end);
  
end
function res = projectile1(t,W)
P = W(1:2);
V= W(3:4);

dPdt = V;
dVdt = acceleration1(t,P,V);
res = [dPdt;dVdt];
end
function res = acceleration1(t,P,V)
g = -9.8;
% -sign(V(1)); %debug stuff
% -sign(V(2)); % more dbug
% V.^2;%dbug
cd = .3; %coefficient of drag
p = 1.3; %kg/m^3
Drag = .5*p*V.^2*.0042*cd ;% drag force on both vectors
ax = Drag(1)/(.145*-sign(V(1))); % compute acceleration for x vector
ay = Drag(2)/(.145*-sign(V(2))) + g; %compute acceleration for y vector
res = [ax;ay];
end